package com.cpr.demo.service.mq.impl;

import cn.hutool.core.date.DateTime;
import com.cpr.demo.model.mq.MqReport;
import com.cpr.demo.mycraft.mq.redis.RedisMessage;
import com.cpr.demo.repository.mq.MqReportRepository;
import com.cpr.demo.service.mq.MqReportService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author Chen Panrui
 * created at 2021/10/19 15:59
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class MqReportServiceImpl implements MqReportService {

    private final MqReportRepository mqReportRepository;

    @Override
    public void save(String queueName, RedisMessage message, String node, String role, String mqType) {
        log.info("保存MQ数据-队列={},消息={},节点={},messageId={}", queueName, message.getMessage(), node, message.getMessageId());
        MqReport model = new MqReport();
        model.setMessageId(message.getMessageId());
        model.setQueueName(queueName);
        model.setRole(role);
        model.setMqType(mqType);
        model.setMessage(message.getMessage());
        model.setMessageTime(DateTime.now());
        model.setNode(node);
        mqReportRepository.insert(model);
    }
}
